import Vue from 'vue'
import Router from 'vue-router'
// import subject from '@/components/submanage'

Vue.use(Router)

 const _router = new Router({
  routes: [
    {
      path: '/submanage',
      name: 'submanage',
      component: () => import('@/components/submanage')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/components/login')
    },
    {
      path: '/exam_select',
      name: 'exam_select',
      component: () => import('@/components/title_manage/exam_select')
    },
    {
      path:'/examList',
      name:'examList',
      component:()=>import('@/components/exam/exam_list')
    },
    {
        path:'/startExam',
        name:'startExam',
        component:()=>import('@/components/exam/startExam'),
    },
    {
        path:'/refer_success',
        name:'refer_success',
        component:()=>import('@/components/exam/refer_success'),
    },
    {
        path:'/',
        name:'test',
        component:()=>import('@/components/test'),
    }
  ]
})

// 前置守卫
_router.beforeEach((to, from, next) => {
	console.info("进入路由守卫");
		// 要权限的请进
		// 有权限放过
    // console.log(window.sessionStorage.getItem("user"))
    // 拦截除主页以外的路径
		if (to.name != 'login' && !window.sessionStorage.getItem("user") && to.name != 'test') {
       next({ name: 'login' })
		}else{
      // 根据角色判断是否可以放过
      next();
    }

});

export default _router;
